package correct.day22;

import java.util.Scanner;

public class Test3 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int v = scanner.nextInt();
        int n = scanner.nextInt();
        int[] arr = new int[n + 1];
        for(int i = 1; i <= n; i++) {
            arr[i] = scanner.nextInt();
        }

        int[][] dp = new int[n + 1][v + 1];
        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= v; j++) {
                dp[i][j] = dp[i - 1][j];
                if(j >= arr[i]) {
                    dp[i][j] = Math.max(dp[i][j], dp[i - 1][j - arr[i]] + arr[i]);
                }
            }
        }
        System.out.println(v - dp[n][v]);
    }
}
